<@main.page title="营业执照_Upload">
<link href="/images/assets/plugins/dropzone/css/dropzone.css"
      rel="stylesheet"/>
<!-- 企业信息编辑Edit -->
<!-- Edit Begin -->
<div class="tab-pane " id="tab_2">
    <div class="portlet box yellow">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-reorder"></i>企业证照-营业执照
            </div>
            <div class="tools">
                <a class="collapse" href="javascript:;"></a>
            </div>
        </div>
        <div class="portlet-body form">
            <!-- BEGIN FORM-->
            <p>
                <span class="label label-danger">NOTE:</span>&nbsp; 上传企业证照附件。
            </p>

            <form class="dropzone" id="myDropzone">
                <div class="fallback">
                    <input name="file" type="file" multiple/>
                </div>
            </form>
            <!--/row-->
            <div class="form-actions right">
                <button id="submit-all" disabled="disabled" class="btn green" type="submit">保存</button>
                <button class="btn default" type="button">取 消</button>
            </div>
            <!-- END FORM-->
        </div>
    </div>
</div>
<!-- Edit End -->
</@main.page>
<script type="text/javascript">
    Dropzone.options.myDropzone = {
        url: "WebFormDropzoneDemo.aspx",
        //最大文件大小，单位是 MB
        maxFilesize: 500,
        //指明允许上传的文件类型，格式是逗号分隔的 MIME type 或者扩展名。例如：image/*,application/pdf,.psd,.obj
        acceptedFiles: "image/*",
        //指定上传图片的路径
        //url: "@Url.Action("BatchUpload", "PhotoUpload")",
        //添加上传取消和删除预览图片的链接，默认不添加
        addRemoveLinks: true,
        //关闭自动上传功能，默认会true会自动上传
        //也就是添加一张图片向服务器发送一次请求
        autoProcessQueue: false,
        //允许上传多个照片
        uploadMultiple: true,
        //每次上传的最多文件数，经测试默认为2，坑啊
        //记得修改web.config 限制上传文件大小的节
        parallelUploads: 100,
        init: function () {
            var submitButton = document.querySelector("#submit-all")
            var sendButton=document.querySelector("#send");
            myDropzone = this; // closure
            //为上传按钮添加点击事件
            submitButton.addEventListener("click", function () {
                $('#send').click();
            });
            sendButton.addEventListener("click", function () {
                //手动上传所有图片
                myDropzone.processQueue();
            });
            //当添加图片后的事件，上传按钮恢复可用
            this.on("addedfile", function (file) {
                $("#submit-all").removeAttr("disabled");
            });
            //当上传完成后的事件，接受的数据为JSON格式
            this.on("complete", function (data) {
                if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
                    var res = eval('(' + data.xhr.responseText + ')');
                    var msg;
                    if (res.Result) {
                        msg = "恭喜，已成功上传" + res.Count + "张照片！";
                    } else {
                        msg = "上传失败，失败的原因是：" + res.Message;
                    }
                    $("#message").text(msg);
                    $("#dialog").dialog("open");
                }
            });
            //删除图片的事件，当上传的图片为空时，使上传按钮不可用状态
            this.on("removedfile", function () {
                if (this.getAcceptedFiles().length === 0) {
                    $("#submit-all").attr("disabled", true);
                }
            });
        }
    };
    $(document).ready(function () {

    });
</script>
